package com.njtoyo.taxi.admin.rest.controller.business.geo;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.rest.presenter.business.geo.AllListPresenter;
import com.njtoyo.taxi.admin.rest.presenter.business.geo.RegionListPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.canton.RegionCreateWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.canton.RegionQueryWrapper;
import com.njtoyo.taxi.admin.rest.wrapper.business.canton.RegionUpdateWrapper;
import com.njtoyo.taxi.admin.service.business.geo.GeoCustomerRegionService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

@RestController
@Api(value = "乘客运营区", tags = "乘客运营区")
@RequestMapping("business/geo/customer_region")
public class CustomerRegionController {

    @Autowired
    private GeoCustomerRegionService geoCustomerRegionService;

    @GetMapping("/all")
    @ApiOperation(value = "全部乘客运营区", notes = "无接口权限校验")
    RestResult<List<AllListPresenter>> getAll(@ModelAttribute("admin") AdminUser adminUser) {
        return geoCustomerRegionService.getAll(adminUser);
    }

    @PostMapping
    @ApiOperation(value = "添加乘客运营区", notes = "权限：customer_region_create")
    @PermissionScope(names = {"customer_region_create"})
    RestResult create(@Valid @RequestBody RegionCreateWrapper wrapper) {
        return geoCustomerRegionService.create(wrapper);
    }

    @GetMapping()
    @ApiOperation(value = "乘客运营区列表", notes = "地区列表：权限：customer_region_list")
    @PermissionScope(names = {"customer_region_list"})
    RestResult<IPage<RegionListPresenter>> getList(RegionQueryWrapper wrapper) {
        return geoCustomerRegionService.getList(wrapper);
    }

    @PatchMapping("/{id}")
    @ApiOperation(value = "修改乘客运营区", notes = "权限：customer_region_update")
    @PermissionScope(names = {"customer_region_update"})
    RestResult<Boolean> update(@PathVariable Long id, @RequestBody RegionUpdateWrapper wrapper) {
        return geoCustomerRegionService.update(id, wrapper);
    }
    /**
     * @return
     */
    @PostMapping("/set_customer_region_close")
    RestResult setCustomerRegionClose(@RequestBody Map<String, Object> params) {
        Long id = MapUtil.getLong(params, "id");
        Boolean isClose = MapUtil.getBool(params, "isClose");
        return geoCustomerRegionService.setCustomerRegionClose(id,isClose);
    }
}
